#include"nfastate.h"

NFAState::NFAState() {}
	
void NFAState::includeState(unsigned s) {
	if (s >= includes.size())
		includes.resize(s + 1, false);
	includes[s] = true;
}

void NFAState::excludeState(unsigned s) {
	if (s < includes.size())
		includes[s] = false;
}
	
NFAState::NFAState(unsigned s) {
	includeState(s);
}

NFAState::NFAState(NFAState const & ns) : includes(ns.includes) {}
	
NFAState::~NFAState() {}

bool NFAState::includesState(unsigned s) const {
	return (s < includes.size()) && includes[s];
}

NFAState NFAState::operator+(NFAState const & ns) const {
	NFAState res(*this);
	res += ns;
	return res;
}

NFAState NFAState::operator+(unsigned s)  const{
	NFAState res(*this);
	res += s;
	return res;
}

NFAState & NFAState::operator+=(NFAState const & ns) {
	for(unsigned i = 0; i < ns.includes.size(); i++)
		if (ns.includes[i])
			includeState(i);
	return *this;
}

NFAState & NFAState::operator+=(unsigned s) {
	includeState(s);
	return *this;
}

NFAState & NFAState::operator=(NFAState const & ns) {
	includes = ns . includes;
	return *this;
}

NFAState & NFAState::operator*=(NFAState const & ns) {
	for(unsigned i = 0; i < ns.includes.size(); i++)
		if (!ns.includes[i])
			excludeState(i);
	if (ns.includes.size() < includes.size())
		includes.resize(ns.includes.size());
	return *this;
}

NFAState NFAState::operator*(NFAState const & ns) const {
	NFAState res(*this);
	res *= ns;
	return res;
}

bool NFAState::isEmpty() const {
	bool res = true;
	for (unsigned i = 0; res && (i < includes.size()); i++)
		res = !includes[i];
	return res;
}
